const store = {
  namespaced: true,
  state: {
      userInfo: {},
      menus: null, // 所有的菜单
      menuPermission: [], //当前用户的菜单权限
      currentPath: ''
  },
  mutations: { // 同步操作
      setUserInfo(state, userInfo) {
          state.userInfo = userInfo;
      },
      setMenus(state, menus) {
          state.menus = menus;
      },
      setMenuPermission(state, menuPermission) {
          state.menuPermission = menuPermission;
      },
      setCurrentPath(state, path) {
          state.currentPath = path;
      }
  },
  actions: { // 异步操作

  },
    getters: {
        hasButtonPermission: (state) => (permission) => {
            return ((state.menuPermission||[]).indexOf(permission)>-1);
        },
        hasMenuPermission: (state) => (permission, len) => {
            return ((state.menuPermission||[]).find(item => item.substr(0, len)===permission));
        }
    }
}

export default store
